<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>公共字段</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<script src="/style/public/publicStyle.js"></script>
	<script>
		/*layui.use(['form'], function() {
            var form = layui.form,
                $ = layui.jquery;
            $(function() {
                if(pageloadauthority("/views/jobgroup.html")==true){
                    $("body").attr("style","display:block;");
                    return;
                }
                atuLoginToken();
            })
        });*/
	</script>
	<style type="text/css">
		.layui-table-tool-panel li .layui-form-checkbox[lay-skin=primary] {
			/* width: 100%; */
			padding-left: 28px;
		}

		.layui-table-tool-panel li {
			line-height: 30px;
			-webkit-transition: .5s all;
			transition: .5s all;
			padding-left: 10px;
			padding-right: 47px;
		}
	</style>
</head>

<body >
<div class="weadmin-nav">
			<span class="layui-breadcrumb" style="visibility: visible;">
			<a href="">元数据管理</a><span lay-separator="">/</span>
			<a>
				<cite>公共字段</cite></a>
			</span>
	<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
		<i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<!--表格-->
<div class="weadmin-body">
	<div class="layui-row">
		<table class="layui-hide" id="tableDataList" lay-filter="usertab"></table>
	</div>
</div>
<div class="layui-row" id="tableForm" style="display:none;">
	<div class="layui-col-md10">
		<form class="layui-form layui-from-pane" id="formId" style="margin-top:20px" lay-filter="tableForm">
			<div class="layui-form-item">
				<label class="layui-form-label">指标选择</label>
				<div class="layui-input-block">
					<select name="idIndex" lay-filter="mainSelectIdFilter" lay-verify="required" lay-search="" style="width: 300px" id="mainSelectId">
						<option value="">直接选择或搜索选择</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">基础表</label>
				<div class="layui-input-block" id="dimCheckboxList">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">维度选择</label>
				<div class="layui-input-block">
					<input type="text" name="idTb" id="idTb" autocomplete="off" disabled class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" style="margin-top:40px">
				<div class="layui-input-block">
					<button class="layui-btn  layui-btn-submit " lay-submit="" lay-filter="demo11">保存</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>
</div>
<!--表格操作-->
<script type="text/html" id="op">
	<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
	<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="delete">删除</a>
</script>

<script type="text/html" id="toolbarDemo">
	<input class="text" style="height:35px;width:257px;" name="" id="hiddenFilter" placeholder="根据表名过滤" />
	<button class="layui-btn layui-btn-sm" lay-event="getCheckData">新增</button>
</script>

</body>
<script>
	layui.use(['util','laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element'], function(){
		var util = layui.util;
		var laydate = layui.laydate //日期
				,laypage = layui.laypage //分页
				,layer = layui.layer //弹层
				,table = layui.table //表格
				,carousel = layui.carousel //轮播
				,upload = layui.upload //上传
				,element = layui.element //元素操作
				,form = layui.form;
		var logintoken= null;
		getSharreTieba_LoginToken();
table.render({
elem: '#tableDataList'
,even: true //开启隔行背景
,cellMinWidth: 80
,toolbar: '#toolbarDemo'
,url:global_visit_url_prefix+'/etl/mdMedDmtb/findByPage'
,where:{
	LoginKey:logintoken,
}
,cols: [[
,{field:'idDmtb', title: 'pk', hide:true}
,{field:'idIndex', title: '指标编码'}
,{field:'naIndex', title: '指标名称'}
,{field:'cdDimgrp', title: '维度组'}
,{field:'idTb', title: '表名'}
,{fixed: 'right', title: '操作', align:'center', toolbar: '#op'}
]]
,page: true
,limit:15
});
    /**********************************  数据准备   *************************************/
	$.ajax({
		url: '/etl/mdMedDmtb/findIndex',
		type:'get',
		success: function(data1) {
			var data =data1.data; //提出返回数据中的data
			if (data!== null) {
				$.each(data, function(index, item) { //循环加入 data的元素
					$("#mainSelectId").append('<option value="'+item.id_index+'">'+item.na_index+'</option>');
				});
				form.render('select');
			};
		}
	});
	/**********************************  数据准备完成   *************************************/
	$("body").on("keypress","#hiddenFilter",function(event){
		var content = $(this).val();
		if(event.keyCode == '13') {
			//执行重载
			table.reload('tableDataList', {
				page: {
					curr: 1 //重新从第 1 页开始
				}
				,where: {
					filter: content		//在表格中进行搜索
				}
			});
			$("#hiddenFilter").val(content);
		}
	});
	form.on('select(mainSelectIdFilter)', function(data){
        $("#naIndex").val(data.innerHTML);
        $.ajax({
            url: '/etl/mdMedDmtb/findDimFieldByIdIndex',
            type:'get',
            data:{idIndex:data.value},
            success: function(data1) {
                $("#dimCheckboxList").empty();
                var data =data1.data; //提出返回数据中的data
                if (data!== null) {
                    $.each(data, function(index, item) { //循环加入 data的元素'+item.idPubfld+'
                        $("#dimCheckboxList").append('<input type="checkbox" name="'+item.idPubfld+'" lay-skin="primary" title="'+item.na+'">');
                        if(index==1) {
                            $("#idTb").val(item.idTb);
						}
                    });
                    form.render();
                };
            }
        });
	});
	form.on('submit(demo11)', function(massage) {
	    debugger;
        var field = massage.field;
        var cdDimgrp = [];
        for(var key in field) {
            if(key.startsWith("id_dim_")) {
                cdDimgrp.push(key);
			}
		}
        massage.field.fldDimList=cdDimgrp;
		$.ajax({
			url:'/etl/mdMedDmtb/save',
			type:'post',
			dataType:'json',
			contentType:'application/json;charset=UTF-8',
			data:JSON.stringify(massage.field),
			success:function (msg) {
				debugger;
				table.reload("tableDataList");
			}
		})
	})
	table.on('toolbar(usertab)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id);
		switch(obj.event){
			case 'getCheckData':
				layer.open({
					//layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
					type: 1,
					title: "添加指标维度表",
					area: ['620px', '630px'],
					content: $("#tableForm")//引用的弹出层的页面层的方式加载修改界面表单
				});
                $("#dimCheckboxList").empty();
				break;
		};
	});
});
</script>

</html>